﻿using CastingWellEquipmentGUI.Config;
using CastingWellEquipmentGUI.Model;
using CastingWellEquipmentGUI.Utils;
using CastingWellEquipmentGUI.ViewModel.Common.Command;
using CastingWellEquipmentGUI.ViewModel.Common.WindowsManager;
using Confluent.Kafka;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace CastingWellEquipmentGUI.ViewModel.Pages
{
    public class DrainageSystemPageViewModel : ViewModelBase
    {
        private bool bo = false;
        private string drainagePipeTagValue = "0";
        /// <summary>
        /// 电机左命令
        /// </summary>
        public DelegateCommand SwitchLevelCommand { get; set; }
        /// <summary>
        /// 电机右命令
        /// </summary>
        public DelegateCommand SwitchLevelCommandRight { get; set; }
        /// <summary>
        /// PV铸井液位显示
        /// </summary>
        public string Lable_Level
        {
            get { return TagTool.GetTagValueByFormNameAndControlName(showPageTitle, "Lable_Level"); }
        }
        /// <summary>
        /// PV百分比
        /// </summary>
        public string Lable_Percentage
        {
            get { return TagTool.GetTagValueByFormNameAndControlName(showPageTitle, "Lable_Percentage"); }
        }
        /// <summary>
        /// 跳转页面名称
        /// </summary>
        public DelegateCommand GoToPageCommand { get; set; }
        #region 预检测项目
        private Visibility _PreDetectionVisibility;
        /// <summary>
        /// 预检测状态
        /// 注：控制预检测框显隐
        /// </summary>
        public Visibility PreDetectionVisibility
        {
            get { return _PreDetectionVisibility; }
            set { _PreDetectionVisibility = value; RaisePropertyChanged("PreDetectionVisibility"); }
        }
        /// <summary>
        /// 铸盘排水阀关闭
        /// </summary>
        public Brush Label_PreCheck1
        {
            get
            {
                if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, "Label_PreCheck1") == "true")
                {
                    return Brushes.Red;
                }
                return Brushes.Black;
            }
        }
        /// <summary>
        /// 铸井液正常
        /// </summary>
        public Brush Label_PreCheck2
        {
            get
            {
                if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, "Label_PreCheck2") == "true")
                {
                    return Brushes.Red;
                }
                return Brushes.Black;
            }
        }
        /// <summary>
        /// UTL站电器柜温度正常
        /// </summary>
        public Brush Label_PreCheck3
        {
            get
            {
                if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, "Label_PreCheck3") == "true")
                {
                    return Brushes.Red;
                }
                return Brushes.Black;
            }
        }
        /// <summary>
        /// 回水泵预检正常
        /// </summary>
        public Brush Label_PreCheck4
        {
            get
            {
                if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, "Label_PreCheck4") == "true")
                {
                    return Brushes.Red;
                }
                return Brushes.Black;
            }
        }
        /// <summary>
        /// 紧急水阀测试正常
         #endregion 定义页面执行命令
        #region 定义页面执行命令
        /// <summary>
        /// 更新数据线程
        /// </summary>
        private Thread animationThread = null;
        /// <summary>
        /// 更新数据线程
        /// </summary>
        private Thread tagInfoSyncThread = null;
        public DelegateCommand ShowModalPanelCommand { get; set; }
        /// <summary>
        /// 铸井液位SP设定按钮命令
        /// </summary>
        private string _Button_SPLevel;
        /// <summary>
        /// 停止时间设置
        /// </summary>
        public string Button_SPLevel
        {
            get { return _Button_SPLevel; }
            set
            {
                if (KafkaHelper.SendGatewayChangeTagMessage(showPageTitle, "Button_SPLevel", value))
                {
                    _Button_SPLevel = value;
                    RaisePropertyChanged("Button_SPLevel");
                }
            }
        }
        private string _Button_MotorCV;
        /// <summary>
        /// 电动机CV设定值
        /// </summary>
        public string Button_MotorCV
        {
            get { return _Button_MotorCV; }
            set
            {
                if (KafkaHelper.SendGatewayChangeTagMessage(showPageTitle, "Button_MotorCV", value))
                {
                    _Button_MotorCV = value;
                    RaisePropertyChanged("Button_MotorCV");
                }
            }
        }
        private string _Button_CVValue;
        /// <summary>
        /// 电动机CV设定值
        /// </summary>
        public string Button_CVValue
        {
            get { return _Button_CVValue; }
            set
            {
                if (KafkaHelper.SendGatewayChangeTagMessage(showPageTitle, "Button_CVValue", value))
                {
                    _Button_CVValue = value;
                    RaisePropertyChanged("Button_CVValue");
                }
            }
        }
        private string _Lable_Left_Level;
        public string Lable_Left_Level
        {
            get { return _Lable_Left_Level; }
            set { _Lable_Left_Level = value; RaisePropertyChanged("Lable_Left_Level"); }
        }
        private string _Lable_Right_Level;
        public string Lable_Right_Level
        {
            get { return _Lable_Right_Level; }
            set { _Lable_Right_Level = value; RaisePropertyChanged("Lable_Right_Level"); }
        }
        /// <summary>
        /// 水平控制阀开关显示
        /// </summary>
        private string _Label_ControlValve;
        public string Label_ControlValve
        {
            get { return _Label_ControlValve; }
            set
            {
                _Label_ControlValve = value;
                RaisePropertyChanged("Label_ControlValve");
            }
        }
        /// <summary>
        /// 水平控制阀开关显示URL
        /// </summary>
        private string _Label_ControlValveURL;
        public string Label_ControlValveURL
        {
            get { return _Label_ControlValveURL; }
            set
            {
                _Label_ControlValveURL = value;
                RaisePropertyChanged("Label_ControlValveURL");
            }
        }
        /// <summary>
        /// 液位仪
        /// </summary>
        private string _Label_LevelSymbol;
        public string Label_LevelSymbol
        {
            get { return _Label_LevelSymbol; }
            set
            {
                _Label_LevelSymbol = value;
                RaisePropertyChanged("Label_LevelSymbol");
            }
        }
        /// <summary>
        /// 液位仪HH
        /// </summary>
        private string _LevelSymbol_HH;
        public string LevelSymbol_HH
        {
            get { return _LevelSymbol_HH; }
            set
            {
                _LevelSymbol_HH = value;
                RaisePropertyChanged("LevelSymbol_HH");
            }
        }
        /// <summary>
        /// 液位仪H
        /// </summary>
        private string _LevelSymbol_H;
        public string LevelSymbol_H
        {
            get { return _LevelSymbol_H; }
            set
            {
                _LevelSymbol_H = value;
                RaisePropertyChanged("LevelSymbol_H");
            }
        }
        /// <summary>
        /// 液位仪L
        /// </summary>
        private string _LevelSymbol_L;
        public string LevelSymbol_L
        {
            get { return _LevelSymbol_L; }
            set
            {
                _LevelSymbol_L = value;
                RaisePropertyChanged("LevelSymbol_L");
            }
        }
        /// <summary>
        /// 液位仪LL
        /// </summary>
        private string _LevelSymbol_LL;
        public string LevelSymbol_LL
        {
            get { return _LevelSymbol_LL; }
            set
            {
                _LevelSymbol_LL = value;
                RaisePropertyChanged("LevelSymbol_LL");
            }
        }
        private string _LevelImageUrl;
        public string LevelImageUrl
        {
            get { return _LevelImageUrl; }
            set
            {
                _LevelImageUrl = value;
                RaisePropertyChanged("LevelImageUrl");
            }
        }
        private string _LevelImageUrlRight;
        public string LevelImageUrlRight
        {
            get { return _LevelImageUrlRight; }
            set
            {
                _LevelImageUrlRight = value;
                RaisePropertyChanged("LevelImageUrlRight");
            }
        }
        #endregion 定义页面执行命令
        /// <summary>
        /// 当前窗体名称
        /// </summary>
        private const string showPageTitle = "DrainageSystemPage";
        public DrainageSystemPageViewModel()
        {
            LevelSymbol_HH = "/images/DrainageSystem/LevelSymbol/HH.png";
            LevelSymbol_H = "/images/DrainageSystem/LevelSymbol/H_A.png";
            LevelSymbol_L = "/images/DrainageSystem/LevelSymbol/L_A.png";
            LevelSymbol_LL = "/images/DrainageSystem/LevelSymbol/LL_A.png";
            LevelImageUrl = "/images/DrainageSystem/HeavyDutyPlasticCentrifugalLumpCyan.png";
            Lable_Right_Level = "次";
            // 初始化命令
            initCommand();
            // 消息通道注册
            initMessenger();
            // 初始化基础信息
            initBaseSet();
            //初始化线程
            initThread();
        }
        /// <summary>
        /// 初始化命令
        /// </summary>
        private void initCommand()
        {
            // 页面跳转
            GoToPageCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(changeTabHandler)
            };
            SwitchLevelCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(SwitchLightHandler)
            };
            SwitchLevelCommandRight = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(SwitchLightHandler)
            };
            // 数值设定按钮命令
            ShowModalPanelCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(showModalPanelHandler)
            };
        }
        /// <summary>
        /// 切换命令方法
        /// </summary>
        /// <param name="obj"></param>
        private void SwitchLightHandler(object obj)
        {
            // 获取参数，此处参数为按钮名称
            string param = obj.ToString();
            WindowManager.ShowModalOnOrOfffAndZhuOrFuPanel("OnOrOffAndZhuOrFuPanel", showPageTitle + param);

        }
        /// <summary>
        /// 初始化线程
        /// </summary>
        private void initThread()
        {
            // 数据线程
            animationThread = new Thread(animationThreadFunc);
            animationThread.SetApartmentState(ApartmentState.STA);
            animationThread.IsBackground = true;
            animationThread.Start();
            // 数据线程
            tagInfoSyncThread = new Thread(syncThreadFunc);
            tagInfoSyncThread.SetApartmentState(ApartmentState.STA);
            tagInfoSyncThread.IsBackground = true;
            tagInfoSyncThread.Start();

        }
        /// <summary>
        /// 初始化基础信息
        /// </summary>
        private void initBaseSet()
        {
            // 页面初始化
            HashSet<Control> tempHashSet = SysCommon.getCurrentControl(showPageTitle);
            if (tempHashSet.Count > 0)
            {
                DoChanged(tempHashSet);
            }
            /** 设定值初始化 **/
            _Button_SPLevel = TagTool.GetTagValueByFormNameAndControlName(showPageTitle, "Button_SPLevel");
            RaisePropertyChanged("Button_SPLevel");
            /** 设定值初始化 **/
            _Button_MotorCV = TagTool.GetTagValueByFormNameAndControlName(showPageTitle, "Button_MotorCV");
            RaisePropertyChanged("Button_MotorCV");
            /** 设定值初始化 **/
            _Button_CVValue = TagTool.GetTagValueByFormNameAndControlName(showPageTitle, "Button_CVValue");
            RaisePropertyChanged("Button_CVValue");
        }
        /// <summary>
        /// 消息通道注册
        /// ViewModel之间数据通信使用，整个项目全局唯一
        /// </summary>
        private void initMessenger()
        {
            //Lable_Left_Level = "主";
            // 铸井液位SP设置
            Messenger.Default.Register<string>(this, showPageTitle + "Button_SPLevel", (message) =>
            {
                Button_SPLevel = message.ToString();
            });
            //电机CV值设置
            Messenger.Default.Register<string>(this, showPageTitle + "Button_MotorCV", (message) =>
            {
                Button_MotorCV = (message.ToString());
            });
            //百分比值设置
            Messenger.Default.Register<string>(this, showPageTitle + "Button_CVValue", (message) =>
            {
                Button_CVValue = (message.ToString());
            });
            //设置左侧电机
            Messenger.Default.Register<string>(this, showPageTitle + "Button_LevelLeft", (message) =>
            {
                setLevelLeftZhu(message.ToString());
            });
            //设置右侧电机
            Messenger.Default.Register<string>(this, showPageTitle + "Button_LevelRight", (message) =>
            {
                setLevelRightZhu(message.ToString());
            });

            //页面切换执行控件刷新
            Messenger.Default.Register<string>(this, showPageTitle + "_DoChange", (message) =>
            {
                HashSet<Control> tempHashSet = SysCommon.getCurrentControl(showPageTitle);
                if (tempHashSet.Count > 0)
                {
                    DoChanged(tempHashSet);
                }
            });
        }
        /// <summary>
        /// 左侧电机设置
        /// </summary>
        /// <param name="message"></param>
        private void setLevelLeftZhu(string message)
        {
            if (message == "" || message == null)
            {
                return;
            }
            if (message =="ON")
            {
                //设置左侧电机启动停止
                if (KafkaHelper.SendGatewayChangeTagMessage(showPageTitle, "Button_LevelLeft", "true"))
                {
                    LevelImageUrl = "/images/DrainageSystem/HeavyDutyPlasticCentrifugalLumpGreen.png";
                }
            }
            if (message=="OFF")
            {
                if (KafkaHelper.SendGatewayChangeTagMessage(showPageTitle, "Button_LevelLeft1", "true"))
                {
                    LevelImageUrl = "/images/DrainageSystem/HeavyDutyPlasticCentrifugalLumpCyan.png";
                }
            }
            if (message == "ZHU")
            {
                //设置左侧电机主辅
                if (KafkaHelper.SendGatewayChangeTagMessage(showPageTitle, "Button_LevelLeftZhu", "true"))
                {
                    Lable_Left_Level = "主";
                }
            }
            if (message == "CI")
            {
                if (KafkaHelper.SendGatewayChangeTagMessage(showPageTitle, "Button_LevelLeftFu", "true"))
                {
                    Lable_Left_Level = "次";
                }
            }
        }
        /// <summary>
        /// 右侧电机设置
        /// </summary>
        /// <param name="message"></param>
        private void setLevelRightZhu(string message)
        {
            if (message == "" || message == null)
            {
                return;
            }
            if (message == "ON")
            {
                //设置左侧电机启动停止
                if (KafkaHelper.SendGatewayChangeTagMessage(showPageTitle, "Button_LevelRight", "true"))
                {
                    LevelImageUrlRight = "/images/DrainageSystem/HeavyDutyPlasticCentrifugalLumpGreen.png";
                }
            }
            if (message == "OFF")
            {
                if (KafkaHelper.SendGatewayChangeTagMessage(showPageTitle, "Button_LevelRight1", "true"))
                {
                    LevelImageUrlRight = "/images/DrainageSystem/HeavyDutyPlasticCentrifugalLumpCyan.png";
                }
            }
            if (message == "ZHU")
            {
                //设置左侧电机主辅
                if (KafkaHelper.SendGatewayChangeTagMessage(showPageTitle, "Button_LevelRightZhu", "true"))
                {
                    Lable_Right_Level = "主";
                }
            }
            if (message == "CI")
            {
                if (KafkaHelper.SendGatewayChangeTagMessage(showPageTitle, "Button_LevelRightFu", "true"))
                {
                    Lable_Right_Level = "次";
                }
            }
        }
        /// <summary>
        /// 执行动作
        /// </summary>
        /// <param name="hashSet"></param>
        private void DoChanged(HashSet<Control> hashSet)
        {
            //遍历返回的控件信息刷新对应的控件
            foreach (Control item in hashSet)
            {
                switch (item.ControlName)
                {

                    /** 水平控制阀开关显示 **/
                    case "Label_ControlValve":
                        drainagePipeTagValue = TagTool.GetTagValueByFormNameAndControlName(showPageTitle, item.ControlName);
                        break;
                    /** 液位仪 **/
                    case "Label_LevelSymbol":
                        if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, item.ControlName) == "0")
                        {
                            LevelSymbol_HH = "/images/DrainageSystem/LevelSymbol/HH.png";
                            LevelSymbol_H = "/images/DrainageSystem/LevelSymbol/H_A.png";
                            LevelSymbol_L = "/images/DrainageSystem/LevelSymbol/L_A.png";
                            LevelSymbol_LL = "/images/DrainageSystem/LevelSymbol/LL_A.png";
                        }
                        if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, item.ControlName) == "1")
                        {
                            LevelSymbol_HH = "/images/DrainageSystem/LevelSymbol/HH.png";
                            LevelSymbol_H = "/images/DrainageSystem/LevelSymbol/H_A.png";
                            LevelSymbol_L = "/images/DrainageSystem/LevelSymbol/L_A.png";
                            LevelSymbol_LL = "/images/DrainageSystem/LevelSymbol/LL.png";
                        }
                        if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, item.ControlName) == "2")
                        {
                            LevelSymbol_HH = "/images/DrainageSystem/LevelSymbol/HH.png";
                            LevelSymbol_H = "/images/DrainageSystem/LevelSymbol/H_A.png";
                            LevelSymbol_L = "/images/DrainageSystem/LevelSymbol/L.png";
                            LevelSymbol_LL = "/images/DrainageSystem/LevelSymbol/LL.png";
                        }
                        if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, item.ControlName) == "3")
                        {
                            LevelSymbol_HH = "/images/DrainageSystem/LevelSymbol/HH_A.png";
                            LevelSymbol_H = "/images/DrainageSystem/LevelSymbol/H.png";
                            LevelSymbol_L = "/images/DrainageSystem/LevelSymbol/L.png";
                            LevelSymbol_LL = "/images/DrainageSystem/LevelSymbol/LL.png";
                        }
                        break;
                    /** 左侧电机主 **/
                    case "Button_LevelLeftZhu":
                        if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, item.ControlName) == "true")
                        {
                            Lable_Left_Level = "主";
                        }
                        break;
                    /** 左侧电机辅 **/
                    case "Button_LevelLeftFu":
                        if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, item.ControlName) == "true")
                        {
                            Lable_Left_Level = "次";
                        }
                        break;
                    /** 左侧电机主 **/
                    case "Button_LevelLeft":
                        if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, item.ControlName) == "true")
                        {
                            LevelImageUrl = "/images/DrainageSystem/HeavyDutyPlasticCentrifugalLumpGreen.png";
                        }
                        break;
                    /** 左侧电机辅 **/
                    case "Button_LevelLeft1":
                        if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, item.ControlName) == "true")
                        {
                            LevelImageUrl = "/images/DrainageSystem/HeavyDutyPlasticCentrifugalLumpCyan.png";
                        }
                        break;
                    /** 右侧电机主 **/
                    case "Button_LevelRightZhu":
                        if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, item.ControlName) == "true")
                        {
                            Lable_Right_Level = "主";
                        }
                        break;
                    /** 右侧电机辅 **/
                    case "Button_LevelRightFu":
                        if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, item.ControlName) == "true")
                        {
                            Lable_Right_Level = "次";
                        }
                        break;
                    /** 右侧电机主 **/
                    case "Button_LevelRight":
                        if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, item.ControlName) == "true")
                        {
                            LevelImageUrlRight = "/images/DrainageSystem/HeavyDutyPlasticCentrifugalLumpGreen.png";
                        }
                        break;
                    /** 右侧电机辅 **/
                    case "Button_LevelRight1":
                        if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, item.ControlName) == "true")
                        {
                            LevelImageUrlRight = "/images/DrainageSystem/HeavyDutyPlasticCentrifugalLumpCyan.png";
                        }
                        break;
                    default:
                        /** 刷新页面值变化信息 **/
                        RaisePropertyChanged(item.ControlName);
                        break;
                }
            }
        }
        /// <summary>
        /// 数值设定按钮命令
        /// </summary>
        /// <param name="obj"></param>
        private void showModalPanelHandler(object obj)
        {
            string param = obj.ToString();
            switch (param)
            {
                // PV温度设定设置
                case "Button_SPLevel":
                    WindowManager.ShowModalDigitalInputPanel("SetCVPanel", showPageTitle + "Button_SPLevel", Button_SPLevel);
                    break;
                // PV温度设定设置
                case "Button_MotorCV":
                    WindowManager.ShowModalDigitalInputPanel("SetCVPanel", showPageTitle + "Button_MotorCV", Button_SPLevel);
                    break;
                // PV百分比设定设置
                case "Button_CVValue":
                    WindowManager.ShowModalDigitalInputPanel("SetCVPanel", showPageTitle + "Button_CVValue", Button_SPLevel);
                    break;
                default:
                    break;
            }
        }
        /// <summary>
        /// 动画线程
        /// </summary>
        private void animationThreadFunc()
        { // 创建消费者对象
            IConsumer<string, object> KafkaConsumer = KafkaHelper.GetConsumer();
            while (true)
            {
                if (SystemConfig.systemState == "预检测" || SystemConfig.systemState == "可见许可")
                {
                    PreDetectionVisibility = Visibility.Visible;
                }
                else
                {
                    PreDetectionVisibility = Visibility.Hidden;
                }
                // 网络中断不进行消费监听
                if (SystemConfig.SystemStatus == "网络中断")
                {
                    Thread.Sleep(1000);
                    continue;
                }
                if (ThreadController.RoundBarDrainageSystemThreadState)
                {
                    //开始消费
                    var result = KafkaConsumer.Consume();
                    if (result != null)
                    {
                        //手动提交
                        KafkaConsumer.Commit(result);
                        //获取消息内容
                        string tagId = result.Message.Value.ToString();
                        HashSet<Control> hashSet = KafkaHelper.UpdateCurrentUserTagValue(Int32.Parse(tagId), KafkaHelper.GetTagValueByKey(tagId.ToString()), showPageTitle);
                        if (hashSet != null && hashSet.Count > 0)
                        {
                            DoChanged(hashSet);
                        }
                    }
                }

                Thread.Sleep(10);
            }
        }
        /// <summary>
        /// 动画线程
        /// </summary>
        private void syncThreadFunc()
        {
            while (true)
            {
                if (ThreadController.RoundBarDrainageSystemThreadState)
                {
                    /** 1、排水管道 动画**/
                    if (drainagePipeTagValue == "0")
                    {
                        // 关闭
                        Label_ControlValveURL = "/images/WaterSupplySystem/ControlValveHorizontalRed.png";
                    }
                    else if (drainagePipeTagValue == "1")
                    {
                        // 关闭中(灰与红切换)
                        if (Label_ControlValveURL == "/images/WaterSupplySystem/ControlValveHorizontal.png")
                        {
                            Label_ControlValveURL = "/images/WaterSupplySystem/ControlValveHorizontalRed.png";
                        }
                        else
                        {
                            Label_ControlValveURL = "/images/WaterSupplySystem/ControlValveHorizontal.png";
                        }
                    }
                    else if (drainagePipeTagValue == "2")
                    {
                        // 打开中(灰与绿切换)
                        if (Label_ControlValveURL == "/images/WaterSupplySystem/ControlValveHorizontal.png")
                        {
                            Label_ControlValveURL = "/images/WaterSupplySystem/ControlValveHorizontalGreen.png";
                        }
                        else
                        {
                            Label_ControlValveURL = "/images/WaterSupplySystem/ControlValveHorizontal.png";
                        }
                    }
                    else if (drainagePipeTagValue == "3")
                    {
                        // 已打开
                        Label_ControlValveURL = "/images/WaterSupplySystem/ControlValveHorizontalGreen.png";
                    }


                    Thread.Sleep(1000);
                }
            }
        }
        /// <summary>
        /// 页面切换
        /// </summary>
        /// <param name="obj"></param>
        private void changeTabHandler(object obj)
        {
            Messenger.Default.Send<string>(obj.ToString(), "GoToPage");
        }
    }
}
